#ifndef __RSC_DECODER_H
#define __RSC_DECODER_H 1

//#include<iostream.h>
//#include<fstream.h>
#include<limits.h>
#include<math.h>
#include"rsc_encoder.h"

class rsc_decoder
{
	private:

	unsigned int N,K,NC,KC,MC,NP,NCW,N_SIGNAL,** V;
	unsigned int *** SET,NSCJ,NS1,NS2,* transmited_binary_sequence;
	unsigned int TAILBITING_SIZE,BLOCK_SIZE,PUNCTURED_BITS,*PUNCTUR_MATRIX;
	unsigned int ZEROTAIL_SIZE;

	unsigned int decoder_set,decoder_axi,PARALLEL;
	unsigned int * decoded_binary_sequence;
	double * SIGNAL,** received_sequence,** bit_metric,* word_metric,** bit_metric1,* word_metric1;
	double BIT_ERROR_RATE,SNR;

	//double *** metrics;

	rsc_encoder *encoder;

	public:

	rsc_decoder(rsc_encoder * _encoder,unsigned int _PUNCTURED_BITS,double _SNR);
   rsc_decoder(rsc_encoder * _encoder,unsigned int _PUNCTURED_BITS);

	~rsc_decoder();

	void set_tailbiting_size(unsigned int _TAILBITING_SIZE,unsigned int _PUNCTURED_BITS)
	{ TAILBITING_SIZE=_TAILBITING_SIZE; BLOCK_SIZE=TAILBITING_SIZE*K; PUNCTURED_BITS=_PUNCTURED_BITS; }

	void set_nonpunctured_size(unsigned int _NP) { NP=_NP; }
	void set_snr(long double _SNR) { SNR=_SNR; }

	void set_zerotail_size(unsigned int _ZEROTAIL_SIZE) { ZEROTAIL_SIZE=_ZEROTAIL_SIZE; }

	void set_zerotail_punctur_matrix(unsigned int * _PUNCTUR_MATRIX);

	void set_decoder_set(unsigned int _decoder_set) { decoder_set=_decoder_set; }

	void set_decoder_axi(unsigned int _decoder_axi) { decoder_axi=_decoder_axi; }

	void set_parallel_decoding(unsigned int _PARALLEL) { PARALLEL=_PARALLEL; }

	void print_codeword(void);

	unsigned int * convert_decimal_binary(unsigned int decimal,unsigned int size);

	long double *** decode_zerotail_sequence_2(long double * received);

   long double * channel_information_log_likelihood_ratio(long double * received);

   long double *** log_probability_density_function(long double * R);
   long double *** log_probability_density_function_2(long double * R,long double * Z,long double mz,long double sigmaz);

   long double *** get_received_sequence(long double * R);

	void print_decoder_data(void);
	void print_decoded_sequence(void);
};

#endif






